package com.guigu.controller;

import com.guigu.dto.FollowUpDiaryDTO;
import com.guigu.service.FollowUpDiaryService;
import com.guigu.vo.FollowUpDiaryVO;
import com.guigu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/FollowUpDiary")
public class FollowUpDiaryController {
    @Autowired
    private FollowUpDiaryService followUpDiaryService;

    @GetMapping("/findAll")
    @ResponseBody
    public Result<List<FollowUpDiaryVO>> findFollowUpDiaryAll(FollowUpDiaryDTO followUpDiaryDTO) {
        List<FollowUpDiaryVO> FollowUpDiaryVOList = this.followUpDiaryService.FindFollowUpDiary(followUpDiaryDTO);
        return new Result<>("200", "true", "成功查询用户列表", FollowUpDiaryVOList);
    }

    @GetMapping("/findIdByName")
    @ResponseBody
    public Result findIdByName(FollowUpDiaryDTO FollowUpDiaryDTO) {
        if (FollowUpDiaryDTO.getName() == null || FollowUpDiaryDTO.getName().isEmpty()) {
            return new Result<>("200", "true", "没有此用户", "无");
        } else {
            FollowUpDiaryVO id = this.followUpDiaryService.findIdByName(FollowUpDiaryDTO);
            if (id != null) {
                return new Result<>("200", "true", "成功查询用户列表", id);
            } else {
                return new Result<>("200", "true", "没有此用户", "无");
            }
        }
    }

    @PostMapping("/saveFollowUp")
    @ResponseBody
    public Result saveFollowUp(@RequestBody FollowUpDiaryDTO followUpDiaryDTO) {
        this.followUpDiaryService.saveFollowUp(followUpDiaryDTO);
        return new Result<>("200", "true", "保存成功", "");
    }

    @PostMapping("/saveFileInfo")
    @ResponseBody
    public Result saveFileInfo(@RequestBody FollowUpDiaryDTO followUpDiaryDTO) {
        this.followUpDiaryService.saveFileInfo(followUpDiaryDTO);
        return new Result<>("200", "true", "成功", "无");
    }
    @PostMapping("/delFollowUpDiary")
    @ResponseBody
    public Result delFollowUpDiary(@RequestBody FollowUpDiaryDTO followUpDiaryDTO)
    {
       this.followUpDiaryService.delFollowById(followUpDiaryDTO);
        return new Result<>("200", "true", "成功", "无");
    }
    @PostMapping("/updateFollowUpDiaryById")
    @ResponseBody
    public  Result updateFollowUpById(@RequestBody FollowUpDiaryDTO followUpDiaryDTO)
    {
        this.followUpDiaryService.updateFollowUpById(followUpDiaryDTO);
        return new Result<>("200", "true", "成功", "无");
    }
}
